/*
 *
 *
Copyright (c) 1998-2001 Aristar, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. The end-user documentation included with the redistribution, if any,
must include the following acknowledgment:

"This product includes software developed by Aristar, Inc. (http://www.aristar.com/)."

Alternately, this acknowledgment may appear in the software itself, if and
wherever such third-party acknowledgments normally appear.

4. The names "Dialect" and "Aristar, Inc." must not be used to endorse or
promote products derived from this software without prior written permission.
For written permission, please contact info@aristar.com.

5. Products derived from this software may not be called "Dialect", nor may
"Dialect" appear in their name, without prior written permission of Aristar, Inc.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
ARISTAR, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This software consists of voluntary contributions made by many individuals
on behalf of Aristar, Inc.  For more information on Aristar, Inc.,
please see <http://www.aristar.com/>.

Portions of this software are based upon software freely available and
written by individuals not associated with Aristar, Inc.  Copyrights are
maintained in the relevant source code files.
 *
 *
 */

// Grid.h : header file

#ifndef GRID_H
#define GRID_H

#include "stdafx.h"

// CGrid window

#define GRID_LEFT_BUTTON 0
#define GRID_RIGHT_BUTTON 1
#define GRID_BUTTON_UP 0
#define GRID_BUTTON_DOWN 1
#define GRID_VK_SLASH 191

#define INVALID_INDEX	0x7FFFFFFF

class CGridEdit : public CEdit
{
protected:
	//{{AFX_MSG(CGridEdit)
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

class CGrid : public CWnd
{
// Construction
public:
	CGrid();
	virtual void Create(CWnd* pParent, const RECT & rect,
						int nrows, int ncols,
						int rowHeight,
						int colWidth[],
						int labelRowHeight=0,
						int labelColWidth=0,
						CFont* cellFont = NULL,
						CFont* labelFont = NULL);

	bool GetEditLabels();
	bool SetEditLabels(bool bEnable);

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CGrid)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual void OnSelChange();
	virtual void OnSelect(int *row, int* col, int* rowsel, int* colsel);
	virtual void OnFocus(int row, int col);
	virtual void OnEdit(int row, int col);
	virtual void OnDelete(int row, int col);
	virtual void OnDelete(int row, int col, int rowsel, int colsel);
	virtual void OnClick(int row, int col, int button, int down);
	virtual int  OnKeypress(int row, int col,
		                    int key, int shift, int control,
							int editing);
	virtual ~CGrid();

	virtual CString Get(int row, int col);
	virtual void Set(int row, int col, CString text);

	void SetID(CString ID);
	CString GetID();

	void SetAutoScroll(int mode);
	void SetAutoFocus(int mode);
	void SetNumberRows(int nrows);
	void SetTopLeftCell(int row, int col);
	void SetSelection(int row, int col);
	void SetSelection(int row, int col, int rowsel, int colsel);

	void GetSelection(int *row, int *col);
	void GetSelection(int *row, int *col, int *rowsel, int *colsel);
	void GetCell(CPoint point, int* row, int *col);
	void GetCellRect(int row, int col, LPRECT rect);
	void Edit(int mode);

protected:
	friend		CGridEdit;
	CString     m_ID;
	CGridEdit	m_Edit;
	CString**	m_pCell;
	CString*	m_pRowLabel;
	CString*	m_pColLabel;
	int			m_nRows;
	int			m_nCols;
	int			m_iRowHeight;
	int*		m_iColWidth;
	int			m_iLabelRowHeight;
	int			m_iLabelColWidth;
	CFont*		m_pLabelFont;
	CFont*		m_pCellFont;
	int			m_iCellFontHeight;

	int			m_iTopRow;
	int			m_iLeftCol;
	int			m_iRow;
	int			m_iCol;
	int			m_iRowSel;
	int			m_iColSel;
	int			m_iEditRow;
	int			m_iEditCol;
	int			m_iAutoScroll;
	int			m_iAutoFocus;
	int			m_iLargeSelection;
	void		AutoScroll();

	// Generated message map functions
protected:
	BOOL Editing();
	bool m_bEditLabels;
	//{{AFX_MSG(CGrid)
	afx_msg void OnPaint();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif